﻿using System;
using System.Data.SqlClient;
using AccessControl.Common;


namespace AccessControl.DataAcess
{
    public class GroupTypeAccess
    {
        public static AccessControlDS.tblGroupTypeDataTable SelectAll()
        {
            using (var cn = new SqlConnection(Util.ConnectionString))
            {
                var cmdSelect = new SqlCommand("SELECT * FROM tblGroupType", cn);
                var tblGroupTypeDataTable = new AccessControlDS.tblGroupTypeDataTable();
                try
                {
                    cn.Open();
                    var reader = cmdSelect.ExecuteReader();
                    while (reader.Read())
                    {
                        var newRow = tblGroupTypeDataTable.NewtblGroupTypeRow();
                        newRow.PkGroupType = (int)reader["PkGroupType"];
                        newRow.GroupTypeName = (String)reader["GroupTypeName"];
                        tblGroupTypeDataTable.AddtblGroupTypeRow(newRow);
                    }
                }
                finally
                {
                    cn.Close();
                }
                return tblGroupTypeDataTable.Rows.Count != 0 ? tblGroupTypeDataTable : null;
            }
        }
    }
}
